using Assets.Scripts.GDK;
using System.IO;
using UnityEngine;

namespace Brick
{
	public class Enemys : MonoBehaviour
	{
		public LevelData loadLevelData;

		private void Start()
		{
			loadLevelData = loadGameConfigJson(GameData.index);
			if (loadLevelData != null)
			{
				foreach (DataItem item in loadLevelData.Stage)
				{
					string id = "Prefabs/Type" + item.type + "/type_" + item.type + "_" + item.typeID;
					GameObject gameObject = gdk_game_manager.loadPrefab(id);
					if ((bool)gameObject)
					{
						int num = item.ID - 1;
						int num2 = 14 - num / 11;
						float num3 = num % 11 + 1;
						gameObject.transform.SetParent(base.gameObject.transform);
						float x = (-6f + num3) * 63f;
						gameObject.GetComponent<RectTransform>().localPosition = new Vector3(x, num2 * 63, 0f);
						if (item.type == 1 || item.type == 3)
						{
							gameObject.GetComponent<itemMake>().setNum(item.num);
							gameObject.GetComponent<ZhangAiWu>().setNum(item.num);
						}
					}
				}
			}
		}

		public void LoadbyJson(int level)
		{
			string path = "Level_" + level.ToString() + "_cfg.json";
			if (!File.Exists(path))
			{
				return;
			}
			StreamReader streamReader = new StreamReader(path);
			if (streamReader != null)
			{
				string text = streamReader.ReadToEnd();
				if (text.Length > 0)
				{
					LevelData levelData = loadLevelData = JsonUtility.FromJson<LevelData>(text);
				}
			}
			streamReader.Close();
		}

		public LevelData loadGameConfigJson(int level)
		{
			string id = "Level_" + level.ToString() + "_cfg.json";
			return gdk_game_manager.loadJsonS<LevelData>(id);
		}
	}
}

